﻿using DevExpress.Data;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.抖音出入库.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.抖音出入库
{
    public partial class Form抖音生产计划 : DevExpress.XtraEditors.XtraForm
    {
        public Form抖音生产计划()
        {
            InitializeComponent();
            this.refresh();
        }

        private void refresh()
        {
            //  查询抖音生产计划数据
            List<DouyinOrderStockUpSummaryDTO> douyinOrderStockUpSummaryDTOs = 抖音订单Service.getDouyinOrderPlan();
            List<DouyinOrderStockUpSummaryVO> list = new List<DouyinOrderStockUpSummaryVO>();
            foreach (DouyinOrderStockUpSummaryDTO item in douyinOrderStockUpSummaryDTOs)
            {
                list.Add(new DouyinOrderStockUpSummaryVO(item));
            }
            this.gridControl抖音生产计划.DataSource = list;
            this.bandedGridView抖音生产计划.GroupSummary.Add(new GridGroupSummaryItem(SummaryItemType.Sum, "totlaQuantity", null, "(数量总合计 = {0})"));
            this.bandedGridView抖音生产计划.RefreshData();
            //  查询昨日下单的抖音备货一览
            //this.gridControl昨日下单待发货.DataSource = 抖音订单Service.getYesterdayDouyinOrderStockUps();
            //this.gridView抖音生产计划.RefreshData();
        }

        private void simpleButton导出Excel_Click(object sender, EventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出Excel";
            fileDialog.Filter = "Excel文件(*.xls)|*.xls";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.gridControl抖音生产计划.ExportToXls(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void simpleButton导出PDF_Click(object sender, EventArgs e)
        {
            this.bandedGridView抖音生产计划.AppearancePrint.HeaderPanel.Font = new System.Drawing.Font("微软雅黑", 10);
            this.bandedGridView抖音生产计划.AppearancePrint.GroupRow.Font = new System.Drawing.Font("微软雅黑", 10);
            this.bandedGridView抖音生产计划.AppearancePrint.Row.Font = new System.Drawing.Font("微软雅黑", 10);
            this.bandedGridView抖音生产计划.ShowPrintPreview();
        }

        private void gridView抖音生产计划_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            //  数量字段为0时不显示
            //  数量字段为0时不显示
            if (e.Column.Name.Equals("gridColumn未来3天发货量")
                || e.Column.Name.Equals("gridColumn未来三到七天发货量")
                || e.Column.Name.Equals("gridColumn七天以后发货量")
                || e.Column.Name.Equals("gridColumn订单数量")
                || e.Column.Name.Equals("gridColumn水洗数量")
                || e.Column.Name.Equals("gridColumn生产批入库数量")
                || e.Column.Name.Equals("gridColumn钉锁数量")
                || e.Column.Name.Equals("gridColumn手缝数量")
                || e.Column.Name.Equals("bandedGridColumn半成品检查数量")
                || e.Column.Name.Equals("gridColumn成品检查数量")
                || e.Column.Name.Equals("bandedGridColumn预库存")
                || e.Column.Name.Equals("bandedGridColumn成品库存")
                || e.Column.Name.Equals("bandedGridColumn凯丹库存")
                || e.Column.Name.Equals("bandedGridColumn柏威年库存")
                )
            {
                try
                {
                    if (Convert.ToString(e.Value).Equals("0"))
                    {
                        e.DisplayText = String.Empty;
                    }
                }
                catch { }
            }
        }
        private void gridView抖音生产计划_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            try
            {
                //  未维护抖音样衣数据标颜色
                if (e.Column.Name == "gridColumnstyleCode")
                {
                    if ("未维护抖音样衣数据".Equals(e.DisplayText))
                    {
                        e.Appearance.BackColor = Color.DeepPink;
                    }
                }
                //  抖音的商品规格列
                if (e.Column.Name == "gridColumn商品规格")
                {
                    e.Appearance.BackColor = Color.Gray;
                }
            }
            catch { }
        }

        private void gridView抖音生产计划_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e)
        {
            if (e.Column.Name == "gridColumn图片")
            {
                Image image1 = (Image)bandedGridView抖音生产计划.GetRowCellValue(e.RowHandle1, e.Column);
                Image image2 = (Image)bandedGridView抖音生产计划.GetRowCellValue(e.RowHandle1, e.Column);
                e.Merge = image1 == image2;
                e.Handled = true;
            }
        }

        private void simpleButton昨日导出excel_Click(object sender, EventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出Excel";
            fileDialog.Filter = "Excel文件(*.xls)|*.xls";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.gridControl昨日下单待发货.ExportToXls(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
    public class DouyinOrderStockUpSummaryVO
    {
        public String styleSizeCd { get; set; } //  尺码
        public Double euroSize { get; set; }    //  排序用欧洲尺码
        public String styleCode { get; set; }
        public String materialCode { get; set; }
        public String inventoryNo { get; set; } //	选购商品	"	【春衫定制】纯色大圆领绸丽绒打底衫保暖吊带背心女21F69"
        public String spec { get; set; }    //	商品规格	"	白色1950_01{get;set;}2XL（140~150斤）"
        /// <summary>
        /// 数量合计
        /// </summary>
        public int threeDays { get; set; }  //  未来3天发货量
        public int sevenDays { get; set; }  //  未来三到七天发货量
        public int overSevenDays { get; set; }  //  七天以后发货量
        public int totlaQuantity { get; set; }   //	总数量
        public int orderQuantity { get; set; }  //  订单数量
        public int washingMarkQuantity { get; set; }   //	水洗数量
        public int wipStockInQuantity { get; set; }  //  生产批入库数量
        public String imageUrl { get; set; }     //  图片url
        public Image photo { get; set; }
        //  工序数量
        public int semiCheckCount { get; set; } //  半成品检查
        public int finishCheckCount { get; set; }   //  成品检查
        public int dingsuoCount { get; set; }   //  钉锁
        public int shoufengCount { get; set; }   //  手缝
        public int preStockIn { get; set; }  //  预库存
        public int garmentStockIn { get; set; }  //  成品库存
        public int kaidanStockIn { get; set; }  //  凯丹库存
        public int baiweinianStockIn { get; set; }  //  柏威年库存
        public int stockIn { get; set; }  //  在库数量合计
        //  价格
        public Double salePrice { get; set; }   //  吊牌价
        public Double onlineSalePrice { get; set; } //  电商零售价
        public DouyinOrderStockUpSummaryVO(DouyinOrderStockUpSummaryDTO dto)
        {
            this.styleSizeCd = dto.styleSizeCd;
            this.euroSize = dto.euroSize;
            if (String.IsNullOrEmpty(dto.styleCode))
            {
                this.styleCode = "未维护抖音样衣数据";
                this.materialCode = dto.spec;

            }
            else
            {
                this.styleCode = dto.styleCode;
                this.materialCode = dto.materialCode;
            }
            this.inventoryNo = dto.inventoryNo;
            this.spec = dto.spec;
            this.threeDays = dto.threeDays;
            this.sevenDays = dto.sevenDays;
            this.overSevenDays = dto.overSevenDays;
            this.totlaQuantity = dto.totlaQuantity;
            this.orderQuantity = dto.orderQuantity;
            this.washingMarkQuantity = dto.washingMarkQuantity;
            this.wipStockInQuantity = dto.wipStockInQuantity;
            this.imageUrl = dto.imageUrl;
            this.semiCheckCount = dto.semiCheckCount;
            this.finishCheckCount = dto.finishCheckCount;
            this.dingsuoCount = dto.dingsuoCount;
            this.shoufengCount = dto.shoufengCount;
            
            try
            {
                //this.photo = FileService.GetImageByUrl(URL.图片url + URL.款式图片路径 + this.inventoryNo + ".jpg");
                this.photo = FileService.GetImageByUrl(dto.imageUrl);
            }
            catch { }
            this.salePrice = dto.salePrice;
            this.onlineSalePrice = dto.onlineSalePrice;
            this.preStockIn = dto.preStockIn;
            this.garmentStockIn = dto.garmentStockIn;
            this.kaidanStockIn = dto.kaidanStockIn;
            this.baiweinianStockIn = dto.baiweinianStockIn;
            this.stockIn = dto.preStockIn + dto.garmentStockIn + dto.kaidanStockIn + dto.baiweinianStockIn;
        }
    }
}